package com.woniuxy.huayoung.controller;

import com.woniuxy.huayoung.entity.TravelNotes;
import com.woniuxy.huayoung.entity.TravelNotesReview;
import com.woniuxy.huayoung.entity.User;
import com.woniuxy.huayoung.result.ResponseResult;
import com.woniuxy.huayoung.service.TravelNotesReviewService;
import com.woniuxy.huayoung.service.TravelNotesService;
import com.woniuxy.huayoung.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/travelnotesreview")
public class TravelNotesReviewController {
    @Resource
    private UserService userService;
    @Resource
    private TravelNotesReviewService travelNotesReviewService;

    //查询当前用户所有的对游记的评论
    @GetMapping("/findTravelNotesReview")
    public ResponseResult<List<TravelNotesReview>> findTravelNotesReview(HttpServletRequest request){
        //得到token
        String token = request.getHeader("authorization");
        int uid = userService.findIdByToken(token);
        List<TravelNotesReview> travelNotesReviews = travelNotesReviewService.findByUid(uid);
        return new ResponseResult<List<TravelNotesReview>>(200,"查询成功",travelNotesReviews);
    }

    //管理员身份查询所有对游记的评论
    @GetMapping("/findAll")
    public ResponseResult<List<TravelNotesReview>> findAll(){
        List<TravelNotesReview> reviews = travelNotesReviewService.findAll();
        return new ResponseResult<List<TravelNotesReview>>(200,"成功",reviews);
    }

    @GetMapping("/verify")
    public ResponseResult<List<TravelNotesReview>> verify(){
        List<TravelNotesReview> reviews = travelNotesReviewService.verify();
        return new ResponseResult<>(200,"成功",reviews);
    }

    @PostMapping("/verifypass")
    public ResponseResult<List<TravelNotesReview>> verifypass(@RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        List<TravelNotesReview> reviews = travelNotesReviewService.verifypass(id);
        return new ResponseResult<List<TravelNotesReview>>(200,"审核通过",reviews);
    }

    @PostMapping("/verifynotpass")
    public ResponseResult<List<TravelNotesReview>> verifyNotPass(@RequestBody Map<String,Object> map){
        List<TravelNotesReview> reviews = travelNotesReviewService.verifynotpass(map);
        return new ResponseResult<>(200,"提交成功",reviews);
    }


}
